package com.lty.zyq.service;

import com.lty.zyq.dao.UserDao;
import com.lty.zyq.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserService {

    @Autowired
    UserDao userDao;

    public User getUser(User user) {
        User result = userDao.findByNameAndDepartment(user.getName(), user.getDepartment());
        if (result != null) {
            return result;
        }
        return userDao.saveAndFlush(user);
    }

    public Integer hasUser(User user) {
        Integer count = userDao.countByIdAndNameAndDepartment(user.getId(), user.getName(), user.getDepartment());
        return count;
    }
}
